package com.lx.dao;

import com.lx.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookDao {
    //通过书名查询图书
    @Select("select * from book where book_name=#{book_name}")
    Book getBookByName(String book_name);
    //通过id查询图书
    @Select("select * from book where id=#{id}")
    Book getBookById(int id);
    //删除图书
    @Delete("delete from book where id=#{id}")
    boolean deleteBook(int id);
    //修改图书
    @Update("update book set book_name=#{book_name},book_author=#{book_author}," +
            "book_time=#{book_time},book_content=#{book_content}," +
            "book_type=#{book_type} where id=#{id}")
    boolean updateBook(Book book);

    //根据id修改user_id
    @Update("UPDATE book SET user_id=#{user_id} where id=#{id}")
    boolean updateBookUserId(@Param("user_id") int user_id, @Param("id") int book_id);
    //计算图书总数
    @Select("select * from book")
    List<Book> countBook();

    //分页查询所有图书
    @Select("select * from book order by id desc limit #{n},#{m}")
    List<Book> getBook(@Param("n") int n, @Param("m") int m);

    //添加图书
    @Insert("INSERT INTO book VALUES(null,null,#{book_name},#{book_author},#{book_time},#{book_content},#{book_type})")
    boolean addBook(
            @Param("book_name") String book_name,
            @Param("book_author") String book_author,
            @Param("book_time") String book_time,
            @Param("book_content") String book_content,
            @Param("book_type") String book_type);

    //通过图书名称进行模糊查询
    @Select("select * from book where book_name like '%${book_name}%'")
    List<Book> getBookByNameLike(@Param("book_name") String book_name);
}

